package chen.web;

import java.util.Enumeration;

import javax.servlet.ServletConfig;
import javax.servlet.ServletContext;
import javax.servlet.ServletException;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.web.servlet.DispatcherServlet;

public class SpringDispatcherInit {

	private static DispatcherServlet ds = null;
		
	static DispatcherServlet getDispatcherServlet(){
		return ds;
	}
	
	public synchronized static void init(final ServletContext context) throws ServletException{
		if(ds != null) return;
		ServletConfig servletConfig = new ServletConfig(){

			@Override
			public String getInitParameter(String arg0) {
				// TODO Auto-generated method stub
				return null;
			}

			@Override
			public Enumeration getInitParameterNames() {
				// TODO Auto-generated method stub
				return new Enumeration(){

					@Override
					public boolean hasMoreElements() {
						// TODO Auto-generated method stub
						return false;
					}

					@Override
					public Object nextElement() {
						// TODO Auto-generated method stub
						return null;
					}
					
				};
			}

			@Override
			public ServletContext getServletContext() {
				// TODO Auto-generated method stub
				return context;
			}

			@Override
			public String getServletName() {
				// TODO Auto-generated method stub
				return "spring-mvc";
			}
			
		};
		ds = new DispatcherServlet();
		ds.init(servletConfig);
	}
	
	
	
}
